﻿using Oracle.ManagedDataAccess.Client;
using System.Data;

namespace ybx_caller.entity
{
    public  class GetDataFromPacs
    {
        public static DataTable QueryDatabase(string b,string e)
        {
            string connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.128.188) (PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=pacs)));User Id=spacsread; Password=spacsread";
            string query = @"SELECT 
                              '420300' area_code,
                              'SYSTHYY' enterprise_id,
                              '2' check_type,
                              b.affirm_date service_date,
                              count(*) quantity from spacs.exams a , spacs.exam_rpt b
                              where a.exam_no = b.exam_no
                              and a.exam_class in  ('CT', 'MRI', '放射', '超声', '消化内镜')
                              and a.exam_status = '70'
                              and b.affirm_date >= :b
                              and b.affirm_date <= :e
                              GROUP BY b.affirm_date";
            DataTable dataTable = new DataTable();
            using (OracleConnection conn = new OracleConnection(connectionString))
            {
                conn.Open();
                using (OracleCommand cmd = new OracleCommand(query, conn))
                {
                    cmd.Parameters.Add(new OracleParameter("b", OracleDbType.Varchar2)).Value = b;
                    cmd.Parameters.Add(new OracleParameter("e", OracleDbType.Varchar2)).Value = e;
                    using (OracleDataAdapter adapter = new OracleDataAdapter(cmd))
                    {
                        adapter.Fill(dataTable);
                    }
                }
            }
            return dataTable;
        }
    }
}
